package client;

import javax.ws.rs.core.Cookie;
import javax.ws.rs.core.MediaType;

import org.apache.wink.client.Resource;
import org.apache.wink.client.RestClient;

import com.ibm.json.java.JSONObject;

public class RESTClient {

    static String   opURI  = "http://localhost:8080/BTTRestWeb/rest/operation/hello";
    static String visitData = "{ \"username\":\"andy\",\"age\":20,\"info\": { \"tel\": \"123456\", \"cellphone\": \"98765\"},\"address\":[{\"city\":\"beijing\",\"postcode\":\"222333\"},{\"city\":\"newyork\",\"postcode\":\"555666\"}]}";
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{
        RestClient restClient = new RestClient();

        // Create new Resource on given URL
        Resource resource = restClient.resource(opURI);
        resource.contentType(MediaType.APPLICATION_JSON);
        resource.header("Accept", "application/json");
        Cookie ck = Cookie.valueOf("JSESSIONID=xxxxxxx");
        resource.cookie(ck);
        JSONObject jo = JSONObject.parse(visitData);
        JSONObject resp = resource.post(JSONObject.class,jo);
        System.out.println(resp);
	}
	
	

}
